home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor1 / jtd.doc < prev    next >
Text File  |  1995-03-31  |  16KB  |  367 lines

  1. (Comp.sys.handhelds) 
  2. Item: 2479 by _kevin at hpcvbbs.UUCP 
  3. Author: [Kevin Jessup] 
  4.   Subj: Julian/Gregorian Conversions 
  5.   Date: Tue Mar 19 1991 
  6.  
  7. =================================================================== 
  8.  
  9. DOCUMENTATION FILE FOR JTD (JULIAN TIME AND DATE) 
  10.            FUNCTIONS FOR THE HP48SX 
  11.                                                     Kevin P. Jessup 
  12.                                                      March 19, 1991 
  13.  
  14. If you downloaded the JTD binary file successfully to your 48SX, you 
  15. now should have a directory named JTD which contains the Julian time 
  16. and date conversion functions.  If you place 'JTD' on the stack and 
  17. execute the BYTES command, you should get the following results... 
  18.  
  19.                 Checksum:   # 243Dh 
  20.                 Byte count:    1987 
  21.  
  22. =================================================================== 
  23.  
  24. Introduction 
  25. ------------ 
  26.  
  27. These routines are patterned after the Julian/Gregorian time and date 
  28. conversion functions that I wrote for the HP28S.  The end result of 
  29. those programs is that they gave the HP28S time, date and alarm 
  30. functions similar to what you already have built into your HP48SX. 
  31. These routines are nothing more than the Julian to Gregorian and 
  32. Gregorian to Julian conversion functions from that software package 
  33. modified to run on the 48SX. 
  34.  
  35. So what do they do? 
  36. ------------------- 
  37. Do not confuse the term "Julian" used in this documentation with the 
  38. Julian calendar developed by Julius Caesar.  "Julian date" as used 
  39. here refers to an absolute number of days that have elapsed since a 
  40. fundamental epoch.  This was developed by astronomers to facilitate 
  41. astronomical observations and to correct errors in Julius Caesars 
  42. calendar that did not accurately represent the time it took for the 
  43. Earth to revolve around the sun. 
  44.  
  45. The fundamental epoch described above is 12 noon January 1st, 4713 BC. 
  46. The number of days that have elapsed since that time is what these 
  47. programs refer to as the "Julian date" or "Juilian day number". 
  48.  
  49. The Julian day number should, by strict definition, also contain the 
  50. time of day as well.  Therefore, these programs produce a fractional 
  51. portion of the day as well where the digits after the decimal point 
  52. in the Julian day represent the portion of the day that has elapsed 
  53. since noon (Julian days increment by one whole digit at noon). 
  54.  
  55. Once the Julian date is known, it is a simple matter to determine the 
  56. day of the week for that date using a simple modulus function as well 
  57. as other date conversion functions such as the number of days between 
  58. two dates. 
  59.  
  60. Generally, all computers will use some variation of these programs if 
  61. they at all intend to maintain the date and time accurately over an 
  62. extended period.  Some computer operating systems use these conversions 
  63. exactly as they are presented here.  One example is the OS9 operating 
  64. system of Microware Corporation for use on the Motorola 68XXX series 
  65. microprocessors. 
  66.  
  67. The 48SX no doubt has some similar functions to convert between Julian 
  68. and Gregorian format but until those SYSEVAL addresses become known, 
  69. these routines will have to do. 
  70.  
  71. For and in-depth description of these and other time and date conversion 
  72. algorithms see the book "Practical Astronomy With Your Calculator" by 
  73. Peter Duffet-Smith.  It is published by Cambridge University Press and 
  74. is available from EduCalc in Laguna Niguel, California. 
  75.  
  76. =================================================================== 
  77.  
  78.                       PROGRAM DESCRIPTIONS 
  79.  
  80. =================================================================== 
  81.  
  82.              Name:     DOW 
  83.              Type:     List 
  84.              Function: Day of week text string list. 
  85.                
  86.              Listing:  { "Sunday" "Monday" "Tuesday" "Wednesday" 
  87.                          "Thursday" "Friday" "Saturday" } 
  88.                
  89.              Notes:    This list is used to get a textual representation 
  90.                        of the day of week based on a real number. 
  91.  
  92.                
  93. ======================================================================= 
  94.  
  95.              Name:     EXPDT 
  96.              Type:     Program 
  97.              Function: Convert compressed Day Month Year to expanded Day 
  98.                        Month Year. 
  99.                
  100.              Listing:  << DUP IP SWAP FP 100 * DUP IP SWAP FP 10000 * >> 
  101.  
  102.              If date mode is DD.MM.YYYY (flag -42 SET) 
  103.              ----------------------------------------- 
  104.              Input:    Level 1:  DD.MMYYYY      real number 
  105.                
  106.              Output:   Level 3:  DD             real number 
  107.                        Level 2:  MM             real number 
  108.                        Level 1:  YYYY           real number 
  109.                
  110.              Example:  Level 1:  27.111956 
  111.                        ->DMY 
  112.                        Level 3:  27 
  113.                        Level 2:  11 
  114.                        Level 1:  1956 
  115.  
  116.              If date mode is MM/DD/YYYY (flag -42 CLEAR) 
  117.              ------------------------------------------- 
  118.                
  119.              Input:    Level 1:  MM.DDYYYY      real number 
  120.                
  121.              Output:   Level 3:  MM             real number 
  122.                        Level 2:  DD             real number 
  123.                        Level 1:  YYYY           real number 
  124.                
  125.              Example:  Level 1:  11.271956 
  126.                        ->DMY 
  127.                        Level 3:  11 
  128.                        Level 2:  27 
  129.                        Level 1:  1956 
  130.                
  131.                
  132. ====================================================================== 
  133.  
  134.                
  135.              Name:     CSPDT 
  136.              Type:     Program 
  137.              Function: Convert expanded Day Month Year to compressed Day 
  138.                        Month Year. 
  139.                
  140.              Listing:  << 10000 / SWAP IP + 100 / SWAP IP + >> 
  141.                
  142.              If date mode is DD.MM.YYYY (flag -42 SET) 
  143.              ----------------------------------------- 
  144.              Input:    Level 3:  DD             real number 
  145.                        Level 2:  MM             real number 
  146.                        Level 1:  YYYY           real number 
  147.                
  148.              Output:   Level 1:  DD.MMYYYY      real number 
  149.                
  150.              Example:  Level 3:  27 
  151.                        Level 2:  11 
  152.                        Level 1:  1956 
  153.                        DMY-> 
  154.                        Level 1:  27.111956  
  155.                
  156.              If date mode is MM/DD/YYYY (flag -42 CLEAR) 
  157.              ------------------------------------------- 
  158.              Input:    Level 3:  MM             real number 
  159.                        Level 2:  DD             real number 
  160.                        Level 1:  YYYY           real number 
  161.                
  162.              Output:   Level 1:  MM.DDYYYY      real number 
  163.                
  164.              Example:  Level 3:  11 
  165.                        Level 2:  27 
  166.                        Level 1:  1956 
  167.                        DMY-> 
  168.                        Level 1:  11.271956  
  169.                
  170.  
  171. ======================================================================== 
  172.  
  173.              Name:     JFIX 
  174.              Type:     Program 
  175.              Function: Utility program used by routines below to adjust 
  176.                        for the current date display mode. 
  177.  
  178.              Listing:  << IF -42 FC? THEN 3 ROLLD SWAP 3 ROLL END >> 
  179.  
  180. ========================================================================= 
  181.  
  182.              Name:     G->JL 
  183.              Type:     Program 
  184.              Function: Convert Gregorian date to Julian date. 
  185.                
  186.              Listing:  << JFIX -> d m y << IF m 3 < THEN m 12 + 'm' STO y 1 - 
  187.                        'y' STO END IF IF 1582 y > THEN 0 ELSE IF 1582 y < 
  188.                        THEN 1 ELSE IF 10 m < THEN 1 ELSE IF 10 m > THEN 0 
  189.                        ELSE IF d 15 < THEN 0 ELSE 1 END END END END END 
  190.                        THEN y 100 / IP DUP 4 / IP 2 3 ROLL - + ELSE 0 END 
  191.                        365.25 y * IP + 30.6001 m 1 + * IP + d + 1720994.5 
  192.                        + >> >> 
  193.                
  194.              If date mode is DD.MM.YYYY (flag -42 SET) 
  195.              ----------------------------------------- 
  196.              Input:    Level 3:  DD.ddddd       real number 
  197.                        Level 2:  MM             real number 
  198.                        Level 1:  YYYY           real number 
  199.                
  200.              Output:   Level 1:  DDDDDDDD.ddd   real number 
  201.  
  202.              If date mode is MM/DD/YYYY (flag -42 CLEAR) 
  203.              ------------------------------------------- 
  204.              Input:    Level 3:  MM             real number 
  205.                        Level 2:  DD.dddd        real number 
  206.                        Level 1:  YYYY           real number 
  207.                
  208.              Output:   Level 1:  DDDDDDDD.ddd   real number 
  209.                
  210.              Example:  Find the Julian date for April 21, 1989 at 3:15:00 
  211.                        PM. 
  212.                
  213.                        Place 3.1500 on the stack.  Then convert the time 
  214.                        to 24 hour format by adding 12 to the time.  Then 
  215.                        convert HMS to HRS by using the function HMS-> 
  216.                        available in the TRIG menu.  Divide by 24 to get 
  217.                        the fractional portion of the date.  Add 21, the 
  218.                        current day of the month.  You now should have 
  219.                        21.6354166667 on the stack.  Continue as shown 
  220.                        below...  
  221.                
  222.                             Level 3:  4 
  223.                             Level 2:  21.6354166667 
  224.                             Level 1:  1989 
  225.                             G->JL 
  226.                             Level 1:  2447638.13542  (the Julian date) 
  227.  
  228.                
  229. ======================================================================== 
  230.  
  231.                
  232.              Name:     JL->G 
  233.              Type:     Program 
  234.              Function: Convert Julian date to Gregorian date. 
  235.                
  236.              Listing:  << .5 + DUP IP SWAP FP 0 0 0 0 -> i f c d e g << 
  237.                        IF i 2299160 > THEN i 1867216.25 - 36524.25 / 
  238.                        IP DUP 4 / IP - 1 + i + ELSE i END 1524 + 'c' STO 
  239.                        c 122.1 - 365.25 / IP 'd' STO d 365.25 * IP 'e' 
  240.                        STO c e - 30.6001 / IP  'g' STO c e - f + g 
  241.                        30.6001 * IP - IF g DUP 13.5 < THEN 1 ELSE IF g 
  242.                        13.5 > THEN 13 ELSE 0 END END - IF DUP 2.5 > THEN 
  243.                        4716 ELSE IF DUP 2.5 < THEN 4715 ELSE 0 END END 
  244.                        d SWAP - JFIX >> >> 
  245.                
  246.              If date mode is DD.MM.YYYY (flag -42 SET) 
  247.              ----------------------------------------- 
  248.              Input:    Level 1:  DDDDDDDD.ddd   real number 
  249.                
  250.              Output:   Level 3:  DD.ddddd       real number 
  251.                        Level 2:  MM             real number 
  252.                        Level 1:  YYYY           real number 
  253.                
  254.              If date mode is MM/DD/YYYY (flag -42 CLEAR) 
  255.              ------------------------------------------- 
  256.              Input:    Level 1:  DDDDDDDD.ddd   real number 
  257.                
  258.              Output:   Level 3:  MM             real number 
  259.                        Level 2:  DD.dddd        real number 
  260.                        Level 1:  YYYY           real number 
  261.                
  262.              Example:  Find the Gregorian equivalent of Julian day 
  263.                        number 2435804.5 
  264.                
  265.                        Level 1:  2435804.5 
  266.                        JL->G 
  267.                        Level 3:  11 
  268.                        Level 2:  27 
  269.                        Level 1:  1956 
  270.                
  271.                
  272. ===================================================================== 
  273.  
  274.              Name:     LPYR 
  275.              Type:     Program 
  276.              Function: Determines if year is a leap year. 
  277.                
  278.              Listing:  << -> y << y 4 MOD NOT y 100 MOD AND y 400 MOD 
  279.                        NOT OR >> >> 
  280.                
  281.              Input:    Level 1: yyyy            real number 
  282.                
  283.              Output:   Level 1: n               real number 
  284.                
  285.              Note:     Output is 1 if a leap year, else 0. 
  286.                
  287.              Notes:    None of the other programs require this 
  288.                        routine.  It is provided for your conveniance 
  289.                        only. 
  290.                
  291.  
  292. ===================================================================== 
  293.  
  294.                
  295.              Name:     RDOW 
  296.              Type:     Program 
  297.              Function: Determine day of week given Gregorian date. 
  298.                
  299.              Listing:  << RCLF 0 FIX SWAP EXPDT G->JL 1.5 + 
  300.                        7 MOD SWAP STOF >> 
  301.                
  302.              If date mode is DD.MM.YYYY (flag -42 SET) 
  303.              ----------------------------------------- 
  304.              Input:    Level 1:  DD.MMYYYY      real number 
  305.                
  306.              Output:   Level 1:  n              real number 
  307.                
  308.  
  309.              If date mode is MM/DD/YYYY (flag -42 CLEAR) 
  310.              ------------------------------------------- 
  311.              Input:    Level 1:  MM.DDYYYY      real number 
  312.                
  313.              Output:   Level 1:  n              real number 
  314.                
  315.              Example:  Level 1:  11.271956      Nov 27, 1956 
  316.                        RDOW 
  317.                        Level 1:  2              Tuesday 
  318.                
  319.              Notes:    Output ranges from 0 to 6 for Sunday to Saturday. 
  320.                
  321.                
  322. ======================================================================== 
  323.  
  324.              Name:     SDOW 
  325.              Type:     Program 
  326.              Function: Same as DOW above but output is a text string. 
  327.                
  328.              Listing:  << 'DOW' SWAP RDOW 1 + GET >> 
  329.                
  330.              Example:  Above example would return "Tuesday" to the stack. 
  331.                
  332.                
  333. ========================================================================= 
  334.  
  335.              Name:     JDATE 
  336.              Type:     Program 
  337.              Function: Return todays Julian date. 
  338.                
  339.              Listing:  << DATE EXPDT JFIX 3 ROLL TIME HMS-> 
  340.                           24 / + 3 ROLLD JFIX G->JL >> 
  341.  
  342. ======================================================================= 
  343.  
  344.                
  345.              Name:     J->DT 
  346.              Type:     Program 
  347.              Function: Given a Julian date, returns the time to level 1 
  348.                        and the Gregorian date to level 2. 
  349.                
  350.              Listing:  << JL->G JFIX 3 PICK FP 24 * ->HMS 4 
  351.                           ROLLD CPSDT SWAP >> 
  352.                
  353.                
  354. ======================================================================== 
  355.  
  356.                
  357.              Name:     DT->J 
  358.              Type:     Program 
  359.              Function: Given Gregorian date on level 2 and time on level 1, 
  360.                        returns the Julian date. 
  361.                
  362.              Listing:  << HMS-> 24 / SWAP EXPDT JFIX 4 ROLL 4 ROLL 
  363.                        + 3 ROLLD JFIX G->JL >> 
  364.  
  365.                
  366. ==========================[ END ]================================== 
  367.